package com.xuxin.baby.presenter;

import com.xuxin.baby.bean.AuthenticateBean;
import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.bean.LoginBean;
import com.xuxin.baby.bean.TenantIdBean;
import com.xuxin.baby.contract.LoginContract;
import com.xuxin.baby.model.LoginModel;

/**
 * Created by xu_xin
 * Created on 2020/10/22 0022
 * 验证码登录
 */
public class LoginPresenter implements LoginContract.Presenter {
    private  final LoginModel model;
    private  final LoginContract.View view;

    public LoginPresenter(LoginContract.View view) {
        this.view = view;
        model = new LoginModel();
    }

    @Override
    public void sendCode(String phone, String code) {
        if (null != model) {
            model.sendCode(this, phone, code);
        }
    }

    @Override
    public void getTenantId(String tenancyName) {
        if (null != model) {
            model.getTenantId(this, tenancyName);
        }
    }

    @Override
    public void authenticate(String tenantId, String userNameOrEmailAddress, String password) {
        if (null != model) {
            model.authenticate(this, tenantId, userNameOrEmailAddress, password);
        }
    }

    @Override
    public void login(String tenantId, String token, String phone) {
        if (null != model) {
            model.login(this, tenantId, token, phone);
        }
    }

    @Override
    public void getInfo(String tenantId, String token) {
        if (null != model) {
            model.getInfo(this, tenantId, token);
        }
    }

    @Override
    public void onSuccess(BaseBean baseBean) {
        if (null != view) {
            view.onSuccess(baseBean);
        }
    }

    @Override
    public void onSuccess(TenantIdBean tenantIdBean) {
        if (null != view) {
            view.onSuccess(tenantIdBean);
        }
    }

    @Override
    public void onSuccess(AuthenticateBean authenticateBean) {
        if (null != view) {
            view.onSuccess(authenticateBean);
        }
    }

    @Override
    public void onSuccess(LoginBean loginBean) {
        if (null != view) {
            view.onSuccess(loginBean);
        }
    }

    /**
     * 以下内容复用(用于请求完成后的操作)
     */
    @Override
    public void onError(BaseBean baseBean) {
        if (null != view) {
            view.onError(baseBean);
        }
    }

    @Override
    public void onComplete() {
        if (null != view) {
            view.onComplete();
        }
    }
}